//1.me
class Solution {
public:
    static bool cmp(const vector<int>& act1, const vector<int>& act2)  {// 添加 const 
        if(act1[0] < act2[0]) {
            return true;
        }
        else if(act1[0] > act2[0]) {
            return false;
        }
        else
            return act1[1] < act2[1];

    }
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
       
        vector<vector<int>> ret;
        
        int step=0;
        sort(intervals.begin(), intervals.end(), cmp);
        ret.push_back(intervals[0]);
        for(int i = 1; i < intervals.size(); ++i) {
            if(intervals[i][0] >= ret[step][0] && intervals[i][0] <= ret[step][1] 
            && intervals[i][1] >= ret[step][1] ) {
                
                ret[step][1] =  intervals[i][1];
                
            }
            else if(intervals[i][0] >= ret[step][0] && intervals[i][1] <= ret[step][1] ) {
                continue;
            }
            else {
                ret.push_back(intervals[i]);
                step++;
            }
           
        }
        return ret;
    }
};

//2.合并一些判断条件
class Solution {
public:
    static bool cmp(const vector<int>& act1, const vector<int>& act2)  {
        if(act1[0] != act2[0]) 
            return act1[0] < act2[0];       
        return act1[1] < act2[1];
        
    }   
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
       
        vector<vector<int>> ret;
        sort(intervals.begin(), intervals.end(), cmp); //默认的sort也可以，等价cmp
        ret.push_back(intervals[0]);
        vector<int> last;
        for(int i = 1; i < intervals.size(); ++i) {
            last = ret.back();
            if(intervals[i][0] <= last[1]) 
                ret.back()[1] = max(intervals[i][1], last[1]);
            else
                ret.push_back(intervals[i]);
           
        }
        return ret;
    }
};


